/**
 *
 */
package cn.hg.jfsa.web.controller;

import com.jfinal.kit.StrKit;

import cn.hg.base.jfinal.controller.BaseController;

/**
 * @author Golly
 */
public class IndexController extends BaseController {

	/**
	 * 分类页
	 */
	public void category () {
		String page = this.get(0);
		Integer id = this.getInt(1, null);

		if (StrKit.isBlank(page)) {
			this.renderError(404);
		}

		this.setAttr("PAGE_NAME", page + (id == null ? "" : "-" + id));
		this.setAttr("id", id);
		this.render("/" + page + "_category.html");
	}

	/**
	 * 内容页
	 */
	public void content () {
		String page = this.get(0);
		Integer id = this.getInt(1, null);

		if (StrKit.isBlank(page)) {
			this.renderError(404);
		}

		this.setAttr("PAGE_NAME", page + (id == null ? "" : "-" + id));
		this.setAttr("id", id);
		this.render("/" + page + "_content.html");
	}

	/**
	 * 详情页
	 */
	public void detail () {
		String page = this.get(0);
		Integer id = this.getInt(1, null);

		if (StrKit.isBlank(page)) {
			this.renderError(404);
		}

		this.setAttr("PAGE_NAME", page + (id == null ? "" : "-" + id));
		this.setAttr("id", id);
		this.render("/" + page + "_detail.html");
	}

	/**
	 * 此方法用于测试Error页面
	 */
	public void error () {
		Integer code = this.getInt("code");
		String view = this.get("view");

		if (StrKit.notBlank(view)) {
			this.renderError(code, view + ".html");
		} else {
			this.renderError(code);
		}

	}

	/*
	 * 首页<br> (non-Javadoc)
	 * @see cn.hg.base.controller.BaseController#index()
	 */
	@Override
	public void index () {
		this.setAttr("PAGE_NAME", "/");
		this.render("/index.html");
	}

	/**
	 * 列表页
	 */
	public void list () {
		String page = this.get(0);
		Integer id = this.getInt(1, null);

		if (StrKit.isBlank(page)) {
			this.renderError(404);
		}

		this.setAttr("PAGE_NAME", page + (id == null ? "" : "-" + id));
		this.setAttr("id", id);
		this.render("/" + page + "_list.html");
	}

	/**
	 * 推荐页
	 */
	public void recommend () {
		String page = this.get(0);
		this.render("/" + page + "_recommend.html");
	}

	/**
	 * 结果页
	 */
	public void result () {
		String page = this.get(0);
		String word = this.get("word", null);
		// if (StrKit.isBlank(page)) {
		// this.renderError(500);
		// }
		this.setAttr("PAGE_NAME", page);
		this.setAttr("word", word);
		this.render("/" + page + "_result.html");
	}

}
